<?php

/**
 *      收款记录控制器
 *      [X-Mis] (C)2007-2099  
 *      This is NOT a freeware, use is subject to license terms
 *      http://www.seemine.cn
 *      tel:(028)82685343
 *      qq:16129825
 */

namespace Home\Controller;
use Think\Controller;

class ShouController extends CommonController{

   public function _initialize() {
        parent::_initialize();
        $this->dbname = "proout";
    }
	
   function _filter(&$map) {
	  // if(!in_array(session('uid'),C('ADMINISTRATOR'))){
	  //   $map[]=array("uid"=>array('EQ', session("uid")),"juid"=>array('like','%'.session("uid").'%'),"_logic"=>"or");
	  //  }
   	if(!in_array(session('uid'),C('ADMINISTRATOR'))){
		$map['uid'] = array('EQ', session("uid"));
	   }

	}
	
   public function _befor_index(){ 
   
   }
  
  
  public function _befor_add(){
	  $attid=time();
	  $this->assign('attid',$attid);
    
  }
	
   public function _after_add($id){
    
   }

  public function _befor_insert($data){
	M("hetong")->where('id='.I("jhid"))->setInc('yishou',I("jine"));
	M("hetong")->where('id='.I("jhid"))->setDec('weishou',I("jine"));
	$data['addm']=date("Y-m",time());
	return $data;
  }
  
  public function _befor_edit(){
     $model = D($this->dbname);
	 $info = $model->find(I('get.id'));
	 $attid=$info['attid'];
	 $this->assign('attid',$attid);
  }
   
  public function _befor_update($data){

  }
  
    public function _after_edit($id){
     
   }

   public function _befor_del($id){
	  
   }

   public function outxls() {
		$model = D($this->dbname);
		$map = $this->_search();
		if (method_exists($this, '_filter')) {
			$this->_filter($map);
		}
		$list = $model->where($map)->field('id,jpname,hytitle,hyxming,hyphone,jpzongjia,addtime')->select();
	    $headArr=array('ID','产品','客户名称','联系人','联系电话','应收货款','添加时间');
	    $filename='应收货款';
		$this->xlsout($filename,$headArr,$list);
	}
	
	public function fenxi(){
	 $this->display();
	}
		public function view() {
	    $model = D($this->dbname);
		$id = $_REQUEST [$model->getPk()];
		$vo = $model->getById($id);
		$this->assign('Rs', $vo);
		$this->display();
	}
 /**
     * 列表页面
     */
 public function xiaoshou(){
	import("Org.Util.Chart");
    $chart = new \Chart;
	for($i=1;$i<=12;$i++){ 	
			$info=$info.",".$i;
			if($i<10){
			$co =M('proout')->where(array('addm'=>date("Y",time())."-0".$i))->SUM('zongjiajin');
			}else{
			$co =M('proout')->where(array('addm'=>date("Y",time())."-".$i))->SUM('zongjiajin');
			}
			$count=$count.",".$co;
		}
    $title = $user.date("Y",time()).'年销售金额'; 
    $data = explode(",", substr ($count, 1)); 
    $size = 140; 
    $width = 750; 
    $height = 300; 
    $legend = explode(",", substr ($info, 1));
    ob_end_clean();
    $chart->createcolumnar($title,$data,$size,$height,$width,$legend);
	}

	
	

}